package com.lx.base.config.converter;


import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;

import java.io.IOException;
import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * @author lixing
 * @date 2022/6/29 13:38
 */
public class LocalDateJacksonConverter  extends JsonDeserializer<LocalDate> {

    @Override
    public LocalDate deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
        LocalDateTimeJacksonConverter localDateTimeJacksonConverter=new LocalDateTimeJacksonConverter();
        LocalDateTime localDateTime=localDateTimeJacksonConverter.deserialize(p,ctxt);
        if(localDateTime==null){
            return null;
        }
      return localDateTime.toLocalDate();
    }
    @Override
    public Class<?> handledType() {
        return LocalDate.class;
    }
}

